package com.test.springboot3.springboot3testdemo1;

import com.test.springboot3.springboot3testdemo1.entity.JavaStackComponent;
import com.test.springboot3.springboot3testdemo1.entity.JavastackProperties;
import com.test.springboot3.springboot3testdemo1.entity.MemberProperties;
import com.test.springboot3.springboot3testdemo1.entity.OtherMember;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableCaching
@EnableScheduling
@EnableAsync
@ServletComponentScan
@RequiredArgsConstructor
@ConfigurationPropertiesScan
// @EnableConfigurationProperties(value = {JavastackProperties.class, MemberProperties.class})
@SpringBootApplication
@Slf4j
public class Springboot3TestDemo1Application {
  private final JavastackProperties javastackProperties;
  private final JavaStackComponent javaStackComponent;
  private final MemberProperties memberProperties;
  private final OtherMember otherMember;
  private final JdbcTemplate jdbcTemplate;

  public static void main(String[] args) {
    SpringApplication application = new SpringApplication(Springboot3TestDemo1Application.class);
    application.setAddCommandLineProperties(false);
    application.run(args);
  }

  @Bean
  public CommandLineRunner commandLineRunner() {
    return args -> {
      log.info("javaStackProperties: {}", javastackProperties);
      log.info("javaStackComponent: {}", javaStackComponent);
      log.info("memberProperties: {}", memberProperties);
      log.info("otherMember: {}", otherMember);
      // throw new JavaStackException("出现异常了...");
      final String username =
          jdbcTemplate.queryForObject("select username from t_user where id=2", String.class);
      log.info("username: {}", username);
      final List<Map<String, Object>> idList = jdbcTemplate.queryForList("select id from t_user");
      log.info("idList: {}", idList);
    };
  }
}
